package com.xcity.game.battle.pve.employee.impl;

import com.xcity.game.battle.Battler;
import com.xcity.game.battle.pve.PlayerBattler;
import com.xcity.game.battle.pve.employee.EmployeeSkillBattleContext;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.employee.skill.EmployeeSkill;

public class ReduceTargetHpSkillContext extends EmployeeSkillBattleContext {

	public ReduceTargetHpSkillContext(PlayerBattler player, EmployeeSkill ref) {
		super(player, ref);
		trigger();
	}

	@Override
	public boolean trigger() {
		if (triggeredTimes == 0) {
			triggeredTimes++;
			Battler target = player.getContext().getTarget();
			int n = rnd.nextInt(GameStaticConfig.percentBase);
			if (n < ref.getTemplate().getInitVal(0)) {
				float ratio = ref.getTemplate().getInitVal(1);
				int hp = (int) (target.getHp() - (target.getHp() * ratio / 100));
				target.setHp(hp);
				return true;
			}
		}
		return false;
	}

}
